<template>
  <div>
    <el-dialog center class="global-dialog" v-model="dialogVisablexq" width="1000px"  top="10vh" :show-close="true"
               :close-on-click-modal="false" @close="close">
      <template #title>
        <div class="my-header">
          <el-tabs v-model="tabId" class="demo-tabs">

<!--            <el-tab-pane label="流程图" name="12" v-if="flag == 3">
              <flowChart :processInstanceId="processInstanceId"></flowChart>
            </el-tab-pane>-->

            <el-tab-pane label="基本信息" name="1">

              <el-divider content-position="left">
                <span class="title-line">基本信息</span>
              </el-divider>
              <el-form :model="diaFormxq" ref="DiaFormxq" :rules="rules" label-width="110px" label-position="top"
                       status-icon>
                <el-row :gutter="20">
                  <el-col :span="6">
                    <el-form-item label="专家类型" prop="expertType">
                      <el-select v-model="diaFormxq.expertType" placeholder="请选择" style="width: 100%"
                                 :disabled="flag == 3" clearable>
                        <el-option :label="item.itemText" :value="item.itemValue"
                                   :key="item.itemValue" v-for="item in expertTypeList" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="专家姓名" prop="expertName">
                      <user-list-modal style="width: 100%" :disabled="flag == 3"
                                       v-if="diaFormxq.expertType == 1" v-model="diaFormxq.expertName"
                                       @update:modelValue="handleProjectLeader" :default-users="[]"
                                       :multiple="false" :devType="'platform'" />
                      <el-input v-else placeholder="请输入" v-model="diaFormxq.expertName"
                                @change="diaFormxq.employeeId = diaFormxq.expertName" style="width: 100%"
                                clearable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="性别" prop="genderId">
                      <el-select v-model="diaFormxq.genderId" placeholder="请选择" style="width: 100%"
                                 :disabled="flag == 3" @change="changeGender" clearable>
                        <el-option :label="item.itemText" :value="item.itemValue"
                                   :key="item.itemValue" v-for="item in sexList" />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="出生日期" prop="birthdate">
                      <el-date-picker v-model="diaFormxq.birthdate" type="date" :disabled="flag == 3"
                                      :disabled-date="disabledDate" value-format="YYYY-MM-DD" placeholder="选择日期"
                                      clearable style="width: 100%" @change="changeBirth" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="6">
                    <el-form-item label="员工编号" prop="employeeCode">
                      <el-input placeholder="请输入" v-model="diaFormxq.employeeCode" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="年龄" prop="age">
                      <el-input placeholder="出生日期自动计算" v-model="diaFormxq.age" disabled>
                        <template v-slot:append>岁</template>
                      </el-input>
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="民族" prop="nationId">
                      <el-select clearable v-model="diaFormxq.nationId" placeholder="请选择"
                                 :disabled="flag == 3" @change="changeNation" style="width: 100%">
                        <el-option :label="item.itemText" :value="item.itemValue"
                                   :key="item.itemText" v-for="item in nationList" />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="籍贯" prop="nativePlace">
                      <el-input placeholder="请输入" v-model="diaFormxq.nativePlace" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>

                </el-row>
                <el-row :gutter="20">
                  <el-col :span="6">
                    <el-form-item label="手机号" prop="phone">
                      <el-input placeholder="请输入" v-model="diaFormxq.phone" style="width: 100%"
                                :disabled="flag == 3" maxlength="11" clearable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="工作所在地" prop="workLocation">
                      <el-input placeholder="请输入" v-model="diaFormxq.workLocation" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="最高学历" prop="highestDegreeId">
                      <el-select v-model="diaFormxq.highestDegreeId" placeholder="请选择"
                                 :disabled="flag == 3" @change="changeEducation" style="width: 100%"
                                 clearable>
                        <el-option :label="item.itemText" :value="item.itemValue"
                                   :key="item.itemValue" v-for="item in educationList" />
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :span="6">
                    <el-form-item label="所学专业" prop="specialty">
                      <el-input placeholder="请输入" v-model="diaFormxq.specialty" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="毕业院校" prop="graduationSchool">
                      <el-input placeholder="请输入" v-model="diaFormxq.graduationSchool"
                                :disabled="flag == 3" style="width: 100%" clearable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="毕业年份" prop="graduationYear">
                      <el-date-picker v-model="diaFormxq.graduationYear" type="date"
                                      :disabled="flag == 3" :disabled-date="disabledDate"
                                      value-format="YYYY-MM-DD" placeholder="请选择" clearable style="width: 100%" />
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="参加工作时间" prop="workStartDate">
                      <el-date-picker v-model="diaFormxq.workStartDate" type="date"
                                      :disabled="flag == 3" :disabled-date="disabledDate"
                                      value-format="YYYY-MM-DD" placeholder="请选择" clearable style="width: 100%"
                                      @change="changeWorkDate" />
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row :gutter="20">
                  <el-col :span="6">

                    <el-form-item label="工作年限" prop="workExperience">
                      <el-input placeholder="根据参加时间自动计算" v-model="diaFormxq.workExperience" disabled>
                        <template v-slot:append>年</template>
                      </el-input>
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="所属单位" prop="workUnitName">
                      <popup-tree-input v-if="diaFormxq.expertType == 1" :data="unitList"
                                        :props="popupTreeProps" :prop="deptForm.parentName == null
                                                    ? $t('message.org.top_menu')
                                                    : diaFormxq.workUnitName
                                                    " :node-key="'' + deptForm.parentId"
                                        :current-change-handle="changeValue8" :disabled="flag == 3" />
                      <el-input placeholder="所属单位" v-else v-model="diaFormxq.workUnitName"
                                style="width: 100%" @change="diaFormxq.workUnitId = diaFormxq.workUnitName"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="所属部门" prop="deptName">
                      <popup-tree-input v-if="diaFormxq.expertType == 1" :data="unitList1"
                                        :props="popupTreeProps" :prop="deptForm.parentName == null
                                                    ? $t('message.org.top_menu')
                                                    : diaFormxq.deptName
                                                    " :node-key="'' + deptForm.parentId"
                                        :current-change-handle="changeValue9"  :disabled="flag == 3"/>

                      <el-input placeholder="所属部门" v-model="diaFormxq.deptName" style="width: 100%"
                                :disabled="flag == 3" clearable @change="diaFormxq.deptId = diaFormxq.deptName"
                                v-else />
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="职务" prop="job">
                      <el-input placeholder="请输入" v-model="diaFormxq.job" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-row :gutter="20">
                  <el-col :span="6">
                    <el-form-item label="职称名称" prop="positionId" v-if="diaFormxq.expertType == 1">
                      <el-select v-model="diaFormxq.positionId" :disabled="flag == 3" placeholder="请选择"
                                 style="width: 100%" @change="changePosition" clearable>
                        <el-option :label="item.itemText" :value="item.itemValue"
                                   :key="item.itemValue" v-for="item in positonList" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="职称名称" prop="positionName" v-else>
                      <el-input placeholder="请输入" v-model="diaFormxq.positionName" :disabled="flag == 3"
                                style="width: 100%" clearable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="微信号" prop="wechat">
                      <el-input placeholder="请输入" v-model="diaFormxq.wechat" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="固定电话" prop="telephone">
                      <el-input placeholder="请输入" v-model="diaFormxq.telephone" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="电子邮箱" prop="email">
                      <el-input placeholder="请输入" v-model="diaFormxq.email" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>
                </el-row>


                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="通讯地址" prop="contactAddress">

                      <el-input placeholder="请输入" v-model="diaFormxq.contactAddress" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>

                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="邮政编码" prop="postalCode">
                      <el-input placeholder="请输入" v-model="diaFormxq.postalCode" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>

                  <el-col :span="6">
                    <el-form-item label="传真" prop="fax">
                      <el-input placeholder="请输入" v-model="diaFormxq.fax" style="width: 100%"
                                :disabled="flag == 3" clearable />
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-divider content-position="left">
                  <span class="title-line">专家指标及信息</span>
                </el-divider>


                <el-row :gutter="20">
                  <el-col :span="24">
                    <el-form-item label="擅长领域" prop="expertiseAreaIds">
                      <el-select v-model="diaFormxq.expertiseAreaIds" placeholder="请选择"
                                 :disabled="flag == 3" @change="changeselect" style="width: 100%" multiple
                                 clearable>
                        <el-option :label="item.itemText" :value="item.itemValue"
                                   :key="item.itemText" v-for="item in areaList" />
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="24">
                    <el-form-item label="工作业绩概述:" style="width: 100%" prop="workSummary">
                      <el-input v-model="diaFormxq.workSummary" :rows="3" maxlength="1000"
                                :disabled="flag == 3" type="textarea" placeholder="1000字以内" />
                    </el-form-item>
                  </el-col>

                </el-row>
              </el-form>
            </el-tab-pane>

            <el-tab-pane label="工作经历" name="2">

              <Work :members="diaFormxq.workExperienceList" @paramsChange="getWorkInfo"
                    :countryList="countryList"  :flag="flag"  ></Work>
            </el-tab-pane>
            <el-tab-pane label="学习经历" name="3">
              <Learn :members="diaFormxq.studyExperienceList" @paramsChange="getStudyInfo"
                     :educationList="educationList"  :flag="flag"  ></Learn>
            </el-tab-pane>
            <el-tab-pane label="学术组织任职" name="4">
              <Academic :members="diaFormxq.academicOrganizationList" @paramsChange="getAcademicInfo"  :flag="flag"  >
              </Academic>
            </el-tab-pane>

            <el-tab-pane label="职业资格证书" name="5">
              <Profession :members="diaFormxq.professionalCertificateList" @paramsChange="getProfessInfo"  :flag="flag"  >
              </Profession>
            </el-tab-pane>


            <el-tab-pane label="承担科研的项目" name="6">
              <Research :members="diaFormxq.researchProjectList" @paramsChange="getResarchInfo"  :flag="flag"  ></Research>
            </el-tab-pane>

            <el-tab-pane label="科研学术研究" name="7">
              <Award :members="diaFormxq.academicAwardList" @paramsChange="getAwardInfo"  :flag="flag"  ></Award>
            </el-tab-pane>

            <el-tab-pane label="批准专利" name="8">
              <Approve :members="diaFormxq.patentApprovalList" @paramsChange="getApproveInfo"
                       :classList="classList"  :flag="flag"  ></Approve>
            </el-tab-pane>

            <el-tab-pane label="发表论文" name="9">
              <Papers :members="diaFormxq.papersList" @paramsChange="getParperInfo" :scoreList="scoreList"  :flag="flag"  >
              </Papers>
            </el-tab-pane>

            <el-tab-pane label="学术著作" name="10">
              <Journal :members="diaFormxq.journalsList" @paramsChange="getJournalInfo" :levelList="levelList"  :flag="flag"  >
              </Journal>
            </el-tab-pane>

            <el-tab-pane label="其他" name="11">
              <Other :members="diaFormxq.otherAchievementsList" @paramsChange="getOtherInfo"  :flag="flag"  ></Other>
            </el-tab-pane>
          </el-tabs>
        </div>
      </template>
      <template #footer>

        <div class="dialog-footer" style="float:left" v-if="flag != 3">
          <el-form  :rules="rulesComment" ref="ruleFormRef" :model="ruleForm">
            <el-form-item label="审批意见" prop="comment">
              <el-input :rows="2" type="textarea" placeholder="审批意见" v-model="ruleForm.comment"
                        style="width: 450px" clearable />
            </el-form-item>
          </el-form>
        </div>

        <span class="dialog-footer" style="margin-top:20px">
                    <el-button @click="close">关闭</el-button>
                    <el-button type="primary" @click="save" v-if="flag == 1 || flag == 2">保存</el-button>
                    <el-button type="primary" @click="refuse" v-if="flag != 3">驳回</el-button>
                    <el-button type="primary" @click="pass" v-if="flag != 3">通过</el-button>
                </span>
      </template>
    </el-dialog>

  </div>
</template>

<script >
import flowChart from '@/components/PublicProcess/Chart/flowChart.vue';
import {
  addForm,
  allowProcess,
  editForm,
  getDetailById,
  getDictionary,
  getUser,
  refuseProcess
} from "@/views/expert/api/expertsManager";
import { ElAlert } from 'element-plus';


import * as proxy from "@/constants/proxy";
import request from "@/utils/request";
import UserListModal from '@/views/project/components/UserListModal/index.vue';
import { checkEmailNumber, checkPhoneNumber } from '@/views/science/common/common';
import PopupTreeInput from '@/views/science/components/PopupTreeInput/index.vue';
import PlatformFiles from '@/views/science/components/platformFiles/platformFiles.vue';
import Record from '@/views/science/components/record/record.vue';
import { Modals, tips } from "@/views/science/components/tips/tips";
import { nextTick, onMounted, reactive, ref, toRefs, watch } from "vue";
import Academic from './academic.vue';
import Approve from './approve.vue';
import Award from './award.vue';
import Journal from './journal.vue';
import Learn from './learn.vue';
import Other from './other.vue';
import Papers from './papers.vue';
import Profession from './profession.vue';
import Research from './research.vue';
import Work from './work.vue';

export default {
  components: {
    PlatformFiles, UserListModal, PopupTreeInput, Record, Work, Learn, Academic, Profession, Research, Award, Approve, Papers, Other, Journal, flowChart, ElAlert
  },
  props: {
    dialogVisablexq: {
      type: Boolean,
      default: false,
    },

    // falg  1:新增  2:编辑  3:详情
    flag: {
      type: String,
      default: "1",
    },
    id: {
      type: String,
      default: '',
    }
  },
  setup(props, { emit }) {

    watch(
        () => props.flag,

        (value) => {

          nextTick(() => {

            // 深度监听.只有在id存在的时候调用详情的接口
            if (value == 1) {
              data.diaFormxq.workExperienceList = []
              data.diaFormxq.studyExperienceList = []
              data.diaFormxq.academicOrganizationList = []
              data.diaFormxq.professionalCertificateList = []
              data.diaFormxq.researchProjectList = []
              data.diaFormxq.academicAwardList = []
              data.diaFormxq.patentApprovalList = []
              data.diaFormxq.papersList = []
              data.diaFormxq.journalsList = []
              data.diaFormxq.otherAchievementsList = []

            } else if (value == 2) {

              getDetail(props.id)

            }
            else if (value == 3) {

              getDetail(props.id)

              // data.tabId = '12'
              data.tabId = '1'

            }

          })

        },

        { deep: true, immediate: true }
    );

    // 发送请求
    onMounted(() => {
      // 获取数据字典
      getUserList();

      getUnitList();
      getUnitList1();
      getCodeList()

    });

    const ruleFormRef = ref()


    const ruleForm = reactive({
      comment: '',
    })

    const rulesComment = reactive({
      comment: [
        { required: true, message: '请输入审核意见', trigger: 'change', },
      ]
    })


    let DiaFormxq = ref();
    let data = reactive({
      dealInVisible: false,
      times: null,
      tabId: '1',
      processInstanceId: '',
      taskId: '',
      expertTypeList: [{ itemValue: '1', itemText: '公司内部专家' }, { itemValue: '2', itemText: '公司外部专家' }],
      expertNameList: [],
      unitList: [],
      unitList1: [],
      levelList: [],
      sexList: [],
      classList: [],
      nationList: [],
      areaList: [],
      educationList: [],
      scoreList: [],

      countryList: [],
      positonList: [],
      userList: [],
      projectList: [],//项目
      technologyList: [],//技术分类
      awardList: [],//软著状态
      popupTreeProps: {
        label: 'name',
        children: 'children',
      },
      diaFormxq: {
        type: 1,
        id: '',
        nationId: "",
        nation: "",
        expertType: "",//专家内型
        expertName: "",//专家姓名
        employeeId: "",
        genderId: '',
        gender: "",//性别
        birthdate: "",//出生日期
        employeeCode: '',//员工编号
        workLocation: "",//工作所在地
        nativePlace: '',
        workExperience: "",
        job: '',
        positionId: "",
        positionName: "",
        workUnitId: '',
        workUnitName: '',
        deptId: "",
        deptName: "",
        phone: "",
        highestDegreeId: "",
        highestDegree: "",
        specialty: "",
        graduationSchool: '',
        graduationYear: "",
        workStartDate: '',
        workSummary: "",
        expertiseAreaIds: [],
        expertiseAreas: [],
        academicOrganizationList: [],
        otherAchievementsList: [],
        patentApprovalList: [],
        professionalCertificateList: [],
        researchProjectList: [],
        studyExperienceList: [],
        workExperienceList: [],
        academicAwardList: [],
        papersList: [],
        journalsList: []
      },

      files: [],
      changeLogs: []
    });
    const deptForm = {
      parentId: 0,
      parentName: '',
    }

    // 规则校验
    let rules = reactive({
      expertType: [
        { required: true, message: '请选择专家类型', trigger: 'blur' },
      ],
      workUnitName: [
        { required: true, message: '请选择所属单位', trigger: 'blur' },
      ],
      deptName: [
        { required: true, message: '请选择所属部门', trigger: 'blur' },
      ],
      expertName: [
        { required: true, message: '请选择专家姓名', trigger: 'change', },
      ],
      nationId: [
        { required: true, message: '请选择民族', trigger: 'change', },
      ],
      gender: [
        { required: true, message: '请选择性别', trigger: 'change', },
      ],
      birthdate: [
        { required: true, message: '请选择出生日期', trigger: 'change', },
      ],
      employeeCode: [
        { required: true, message: '请输入员工编号', trigger: 'change', },
      ],
      workLocation: [
        { required: true, message: '请输入工作所在地', trigger: 'change', },
      ],
      job: [
        { required: true, message: '请输入职务', trigger: 'change', },
      ],
      nativePlace: [
        { required: true, message: '请输入籍贯', trigger: 'change', },
      ],
      phone: [
        { required: true, message: '请输入手机号', trigger: 'change' },
        { validator: checkPhoneNumber, trigger: "blur" },
      ],
      highestDegreeId: [
        { required: true, message: '请选择最高学历', trigger: 'change' },
      ],
      positionId: [
        { required: true, message: '请选择职称', trigger: 'change' },
      ],
      positionName: [
        { required: true, message: '请选择职称', trigger: 'change' },
      ],
      specialty: [
        { required: true, message: '请输入所学专业', trigger: 'change' },
      ],
      graduationSchool: [
        { required: true, message: '请输入毕业院校', trigger: 'change' },
      ],
      graduationYear: [
        { required: true, message: '请选择毕业年份', trigger: 'change' },
      ],
      workStartDate: [
        { required: true, message: '请选择参加工作时间', trigger: 'change' },
      ],
      expertiseAreaIds: [
        { required: true, message: '请选择擅长领域', trigger: 'change' },
      ],
      email: [
        { required: true, message: '请输入电子邮箱', trigger: 'change' },
        { validator: checkEmailNumber, trigger: "blur" },
      ],
    });

    let refuse = () => {
      ruleFormRef.value.validate(valid => {
        if (valid) {

          Modals('是否驳回本次内容', '提示', 'warning').then(async () => {

            refuseProcess({
              procInsId: data.processInstanceId,
              comment: ruleForm.comment,
              businessKey: props.id,
              businessType: 'YW04',
              random: (new Date()).valueOf()

            }).then((res) => {

              if (res.data.code == 200) {

                ruleFormRef.value.resetFields();

                emit("changerRefusexq");

              } else {

                tips(res.data.message, 'warning')

              }


            }).catch(() => {
              console.log("点击了取消")
            })

          })



        }
      })


    }

    //通过
    let pass = () => {

      ruleFormRef.value.validate(valid => {
        if (valid) {

          Modals('是否通过本次内容', '提示', 'warning').then(async () => {

            allowProcess({
              procInsId: data.processInstanceId,
              comment: ruleForm.comment,
              businessKey: props.id,
              businessType: 'YW04',
              random: (new Date()).valueOf()
            }).then((res) => {

              if (res.data.code == 200) {
                ruleFormRef.value.resetFields();

                emit("changeSuccess");
              } else {
                tips(res.data.message, 'warning')
              }

            })

          }).catch((error) => {
            console.log(error)
          })

        }
      })

    }

    let dealInCheck = (id) => {

      data.times = setInterval(() => {

        getDetailById(id).then((res) => {


          let resData = res.data.data

          if (resData.status == 2 || resData.status == 1) {

            data.dealInVisible = false

            emit("changeDialogxq", '1');

            clearTimeout(data.times)

          }

        })

      }, 1000);
    }

    // 保存
    let save = () => {
      DiaFormxq.value.validate((valid) => {
        // 校验通过
        if (valid) {
          //flag 1 新增  2 编辑  3  详情
          if (props.flag == 1) {

            data.diaFormxq.id = '';

            addForm(

                data.diaFormxq


            ).then(() => {

              tips("新增成功", "success");

              diaFormxq.value.resetFields();

              emit("changeDialogxq", '1');

            });


          } else {
            editForm(
                data.diaFormxq
            ).then(() => {

              tips("编辑成功", "success");

              DiaFormxq.value.resetFields();

              emit("changeDialogxq", '1');

            });

          }
        } else {

          return tips('请将基本信息补充完整', 'warning')

        }


      });
    }
    // 通过详情查询id

    let getDetail = async (id) => {

      let res = await getDetailById(id);

      data.diaFormxq = res.data.data

      data.processInstanceId = res.data.data.processInstanceId

      data.taskId = res.data.data.taskId



    };

    // 技术分类/软著状态===>数据字典

    let getCodeList = () => {

      getDictionary(['ZJYRC_ZJLX', 'SEX', 'NATIONALITY', 'EDUCATION', 'ZJYRC_ZCMC', 'ZJYRC_SCLY', 'ZJYRC_SZGJ', 'KJSL_PATENT_TYPE', 'KJSL_ACADEMIC_WORK_LEVEL', "KJSL_BUSINESS_SECTOR",]).then((res) => {


        data.sexList = res.data.data.SEX;

        data.nationList = res.data.data.NATIONALITY;

        data.educationList = res.data.data.EDUCATION;

        data.positonList = res.data.data.ZJYRC_ZCMC;

        data.areaList = res.data.data.ZJYRC_SCLY;

        data.countryList = res.data.data.ZJYRC_SZGJ;

        data.classList = res.data.data.KJSL_PATENT_TYPE;

        data.scoreList = res.data.data.KJSL_BUSINESS_SECTOR;


        data.levelList = res.data.data.KJSL_ACADEMIC_WORK_LEVEL;
      });
    };

    let getWorkInfo = (parms) => {

      data.diaFormxq.workExperienceList = parms

    }


    let getStudyInfo = (parms) => {

      data.diaFormxq.studyExperienceList = parms

    }

    let getAcademicInfo = (parms) => {

      data.diaFormxq.academicOrganizationList = parms

    }

    let getProfessInfo = (parms) => {

      data.diaFormxq.professionalCertificateList = parms

    }

    let getOtherInfo = (parms) => {

      data.diaFormxq.otherAchievementsList = parms

    }

    let getResarchInfo = (parms) => {

      data.diaFormxq.researchProjectList = parms

    }

    let getAwardInfo = (parms) => {
      data.diaFormxq.academicAwardList = parms
    }

    let getParperInfo = (parms) => {

      data.diaFormxq.papersList = parms
    }

    let getJournalInfo = (parms) => {

      data.diaFormxq.journalsList = parms
    }

    let getApproveInfo = (parms) => {

      data.diaFormxq.patentApprovalList = parms
    }

    // 项目

    let getUserList = () => {

      getUser({}).then((res) => {

        data.userList = res.data.data;
      });
    };



    let changeEducation = (id) => {
      let itemText = data.educationList.find((item) => item.itemValue == id).itemText;
      data.diaFormxq.highestDegree = itemText
    }
    // 职务Name
    let changePosition = (id) => {
      let itemText = data.positonList.find((item) => item.itemValue == id).itemText;
      data.diaFormxq.positionName = itemText
    }

    let changeGender = (id) => {
      let itemText = data.sexList.find((item) => item.itemValue == id).itemText;
      data.diaFormxq.gender = itemText
    }

    let changeNation = (id) => {
      let itemText = data.nationList.find((item) => item.itemValue == id).itemText;
      data.diaFormxq.nation = itemText
    }

    let handleProjectLeader = (user) => {
      data.diaFormxq.expertName = user.cname
      data.diaFormxq.employeeId = user.userId
      getPeople(user.userCode)
    }

    const getPeople = (id) => {
      return request({
        url: proxy.CHECC_API_CMS + "/user/getList",
        method: "post",
        data: { empcode: id },
      }).then(res => {
        console.log('res', res.data.data.records[0]);
        let resdata = res.data.data.records[0]
        data.diaFormxq.genderId = resdata.gender
        data.diaFormxq.gender = resdata.gendertext
        data.diaFormxq.birthdate = resdata.birth.substring(0, 10)
        //根据出生日期算年龄
        if (data.diaFormxq.birthdate) {
          let birthDayTime = new Date(data.diaFormxq.birthdate).getTime();
          let nowTime = new Date().getTime();
          data.diaFormxq.age = Math.ceil((nowTime - birthDayTime) / 31536000000)
        }
        data.diaFormxq.nationId = resdata.nationDict
        data.diaFormxq.nation = resdata.nation
        data.diaFormxq.phone = resdata.phone
        data.diaFormxq.highestDegreeId = resdata.educationDict
        data.diaFormxq.highestDegree = resdata.educationBackground
        data.diaFormxq.specialty = resdata.typeOfWork
        data.diaFormxq.workStartDate = resdata.hiredate.substring(0, 10)
        //参加工作时间
        if (data.diaFormxq.workStartDate) {
          let DayTime = new Date(data.diaFormxq.workStartDate).getTime();
          let nowTime = new Date().getTime();
          data.diaFormxq.workExperience = Math.ceil((nowTime - DayTime) / 31536000000)
        }
        data.diaFormxq.workUnitName = resdata.orgname
        data.diaFormxq.workUnitId = resdata.orgid
        data.diaFormxq.deptName = resdata.deptName
        data.diaFormxq.deptId = resdata.deptId
        data.diaFormxq.job = resdata.selectOrgs
        data.diaFormxq.positionId = resdata.technicalDict
        data.diaFormxq.positionName = resdata.technicalTitle
        data.diaFormxq.email = resdata.email
      })
    }
    let changeselect = (val) => {
      let arr = []
      data.areaList.forEach(item => {
        for (let i = 0; i < val.length; i++) {
          if (item.itemValue == val[i]) {
            arr.push(item.itemText)
          }
        }
      })
      data.diaFormxq.expertiseAreas = arr
    }

    //   出生计算年龄
    let changeBirth = (value) => {
      let birthDayTime = new Date(value).getTime();
      let nowTime = new Date().getTime();
      data.diaFormxq.age = Math.ceil((nowTime - birthDayTime) / 31536000000)
    }

    let changeWorkDate = (value) => {
      let DayTime = new Date(value).getTime();
      let nowTime = new Date().getTime();
      data.diaFormxq.workExperience = Math.ceil((nowTime - DayTime) / 31536000000)
    }

    let disabledDate = (date) => {
      return date.getTime() > Date.now();
    };

    // 单位公司
    let getUnitList = () => {
      return request({
        url: proxy.CHECC_API_CMS + "/org/getSysOrgList",
        method: "get",
      }).then(res => {
        data.unitList = res.data.data
      })
    };
    // 部门
    let getUnitList1 = () => {
      return request({
        url: proxy.CHECC_API_CMS + "/org/tree",
        method: "get",
      }).then(res => {
        data.unitList1 = res.data.data
      })
    };

    // 关闭清除对话框里面的数据,附件.变更记录也要删除
    let close = () => {
/*      if (props.flag == 3) {
        ruleFormRef.value.resetFields();
      }*/
      data.tabId = '1';
      DiaFormxq.value.resetFields();
      emit("changeDialogxq");

    };
    const changeValue8 = (item) => {
      data.diaFormxq.workUnitId = item.id
      data.diaFormxq.workUnitName = item.name
    }
    const changeValue9 = (item) => {
      data.diaFormxq.deptId = item.id
      data.diaFormxq.deptName = item.name
    }

    return {
      disabledDate,
      DiaFormxq,
      deptForm,
      changeValue8,
      changeValue9,
      getUnitList,
      getUnitList1,
      getWorkInfo,
      getStudyInfo,
      getAcademicInfo,
      getProfessInfo,
      getOtherInfo,
      getResarchInfo,
      getAwardInfo,
      getParperInfo,
      getJournalInfo,
      getApproveInfo,
      rules,
      getUserList,
      getCodeList,
      changeEducation,
      changePosition,
      changeselect,
      changeBirth,
      changeWorkDate,
      changeGender,
      changeNation,
      ...toRefs(data),
      close,
      save,
      ruleForm,
      rulesComment,
      pass,
      dealInCheck,
      ruleFormRef,
      refuse,
      handleProjectLeader
    };
  },
};
</script>

<style scoped lang="scss">
.title-line {
  color: #409EFF;
}

.dialog-footer {
  display: flex;
  justify-content: end;
}

:deep(.el-dialog__body) {
  display: none;
}

// 滚动条
:deep(.demo-tabs > .el-tabs__content) {
  max-height: 500px;
  overflow-y: scroll;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
</style>
